package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * @author xingxing.xiao
 * @date 2020/12/23 16:07
 */
@Getter
public enum CreditLimitStatusEnum {

    FREEZE("0", "enum.creditLimitStatus.name.freeze", ""),
    NORMAL("1", "enum.creditLimitStatus.name.normaL", ""),
    UNKNOWN("404", "--", ""),
    ;

    /**
     * 状态
     */
    private String code;
    /**
     * 名称
     */
    private String name;
    /**
     *
     */
    private String attr;

    CreditLimitStatusEnum(String code, String name, String attr) {
        this.code = code;
        this.name = name;
        this.attr = attr;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public static CreditLimitStatusEnum getByCode(Integer code) {
        for (CreditLimitStatusEnum cacheCode : values()) {
            if (Objects.equals(code, cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

}
